﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RPCenter.WindowsAPI
{
    public class StartExeInService
    {
        public static void SimpleStartExe(string theExeFullPath)
        {

            IntPtr userTokenHandle = IntPtr.Zero;
            ApiDefinitions.WTSQueryUserToken(ApiDefinitions.WTSGetActiveConsoleSessionId(), ref userTokenHandle);

            ApiDefinitions.PROCESS_INFORMATION procInfo = new ApiDefinitions.PROCESS_INFORMATION();
            ApiDefinitions.STARTUPINFO startInfo = new ApiDefinitions.STARTUPINFO();
            startInfo.cb = (uint)System.Runtime.InteropServices.Marshal.SizeOf(startInfo);

            ApiDefinitions.CreateProcessAsUser(
                userTokenHandle,
                theExeFullPath,
                "",
                IntPtr.Zero,
                IntPtr.Zero,
                false,
                0,
                IntPtr.Zero,
                null,
                ref startInfo,
                out procInfo);

            if (userTokenHandle != IntPtr.Zero)
                ApiDefinitions.CloseHandle(userTokenHandle);

            int _currentAquariusProcessId = (int)procInfo.dwProcessId;
        }
    }
}
